package net.hn.hnms.biz.emgcy.service.impl;

import net.hn.hnms.biz.emgcy.domain.RescueHeadquartersPo;
import net.hn.hnms.biz.emgcy.domain.dto.RescueHeadquartersDto;
import net.hn.hnms.biz.emgcy.domain.vo.RescueHeadquartersGroupVo;
import net.hn.hnms.biz.emgcy.domain.vo.RescueHeadquartersVo;
import net.hn.hnms.biz.emgcy.mapper.RescueHeadquartersMapper;
import net.hn.hnms.biz.emgcy.service.RescueHeadquartersService;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: baijiajun
 * @Date: 2022/9/13
 */
@Service
public class RescueHeadquartersServiceImpl implements RescueHeadquartersService {
    @Autowired
    private RescueHeadquartersMapper rescueHeadquartersMapper;

    @Override
    public ResponsePage<RescueHeadquartersVo> pageList(PageQuery pageQuery, RescueHeadquartersDto rescueHeadquartersDto) {
        pageQuery.setPageNum(pageQuery.getPageNum() >= 1 ? (pageQuery.getPageNum() - 1) * pageQuery.getPageSize():0);
        List<RescueHeadquartersVo> list =  rescueHeadquartersMapper.pageList(pageQuery.getPageSize(), pageQuery.getPageNum(), rescueHeadquartersDto);
        if(list.isEmpty()){
            return new ResponsePage<>(new ArrayList(),0);
        }
        return new ResponsePage<>(list,list.get(0).getTotal());
    }

    @Override
    public Boolean add(RescueHeadquartersPo rescueHeadquartersPo) {
        int insert = rescueHeadquartersMapper.insert(rescueHeadquartersPo);
        if(insert>0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean update(RescueHeadquartersPo rescueHeadquartersPo) {
        int update = rescueHeadquartersMapper.updateById(rescueHeadquartersPo);
        if(update>0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean delete(Long id) {
        int delete = rescueHeadquartersMapper.deleteById(id);
        if(delete>0){
            return true;
        }
        return false;
    }

    @Override
    public Map<String, Object> list() {
        HashMap<String, Object> map = new HashMap<>();
        List<RescueHeadquartersVo> postList=rescueHeadquartersMapper.selectPostList();
        RescueHeadquartersVo rescueHeadquarters =rescueHeadquartersMapper.selectPost();
        List<RescueHeadquartersGroupVo> resourceGroups =rescueHeadquartersMapper.selectGroupMember();
        map.put("postList",postList);
        map.put("rescueHeadquarters",rescueHeadquarters);
        map.put("resourceGroups",resourceGroups);
        return map;
    }
}
